#pragma once
#include <string>
#include <sys/un.h>
#include "XnccAddress.h"
namespace xncc {
namespace foundation {
    class UnixDomainAddress final : public XnccAddress
    {
      public:
        using s_ptr = std::shared_ptr<UnixDomainAddress>;
        explicit UnixDomainAddress(const std::string& addr);
        explicit UnixDomainAddress(const struct sockaddr_un& addr);
        UnixDomainAddress() = default;
        ~UnixDomainAddress() override;

        UnixDomainAddress(const UnixDomainAddress&)             = delete;
        UnixDomainAddress(const UnixDomainAddress&&)            = delete;
        UnixDomainAddress& operator=(const UnixDomainAddress&)  = delete;
        UnixDomainAddress& operator=(const UnixDomainAddress&&) = delete;

        [[nodiscard]] auto Type() const -> shared::XNCC_ADDR_TYPE override
        {
            return shared::XNCC_ADDR_TYPE::UNIX_DOMAIN;
        }

        [[nodiscard]] sa_family_t family() const override { return addr_.sun_family; }

        [[nodiscard]] std::string toStr() const override { return sunPath_; }

        [[nodiscard]] const struct sockaddr* getSockAddr() const override
        {
            return reinterpret_cast<const struct sockaddr*>(&addr_);
        }

        [[nodiscard]] socklen_t getSockLen() const override { return static_cast<socklen_t>(sizeof(addr_)); }

        void setSockAddr(const struct sockaddr_un& addr) { addr_ = addr; }

      private:
        struct sockaddr_un addr_ = {};
        const std::string  sunPath_;
    };
}  // namespace foundation
}  // namespace xncc